// pages/amount_warter/amount_water.js
var common = require("../../common/common.js").common;

const app = getApp();

Page({
    /**
   * 页面的初始数据
   */
    data: {
        choose: 1,
        bill: [],
        bill2: []
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        let that = this;
        that.setData({
            domain: app.globalData.domain.slice(0, -10)
        });
        this.getinfo();
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {},
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {},
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {},
    choose_nav: function(e) {
        var that = this;
        var id = e.currentTarget.dataset.id;
        this.setData({
            choose: id
        });
        var choose = this.data.choose;
        var openid = wx.getStorageSync("user").openid;
        if (choose == 2) {
            common.request({
                endpoint: "finance/myextract_apply",
                method: "post",
                data: {
                    openid: openid
                },
                header: {
                    "content-type": "application/json"
                },
                success: function(res) {
                    that.setData({
                        bill2: res.bill
                    });
                }
            });
        }
    },
    getinfo: function() {
        var that = this;
        var openid = wx.getStorageSync("user").openid;
        common.request({
            endpoint: "finance/myextract_bill",
            method: "post",
            data: {
                openid: openid
            },
            header: {
                "content-type": "application/json"
            },
            success: function(res) {
                that.setData({
                    bill: res.bill
                });
            }
        });
    }
});